package com.maxio.controller;

import com.maxio.domain.R;
import com.maxio.domain.dto.DeptDTO.DeptAddDTO;
import com.maxio.domain.dto.DeptDTO.DeptEditDTO;
import com.maxio.domain.query.DeptQuery;
import com.maxio.service.IDeptService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author enhuan
 * @since 2024-05-28
 */
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private IDeptService deptService;

    /**
     * 新增部门信息
     */
    @ApiOperation(value = "新增部门信息")
    @PostMapping("/save")
    public R<?> saveDept(@RequestBody DeptAddDTO addDTO) {
        return R.ok(deptService.saveDept(addDTO));
    }

    /**
     * 单个查询部门信息
     */
    @ApiOperation(value = "单个查询部门信息")
    @GetMapping("/selectById/{id}")
    public R<?> selectDeptById(@PathVariable Long id) {
        return R.ok(deptService.selectById(id));
    }

    /**
     * 修改当前部门信息
     */
    @ApiOperation(value = "修改当前部门信息")
    @PutMapping("/update")
    public R<?> updateDeptById(@RequestBody DeptEditDTO editDTO) {
        return R.ok(deptService.updateDeptById(editDTO));
    }

    /**
     * 单个删除部门信息
     */
    @ApiOperation(value = "单个删除部门信息")
    @DeleteMapping("/delete/{id}")
    public R<?> deleteDeptById(@PathVariable Long id) {
        return R.ok(deptService.deleteById(id));
    }

    /**
     * 分页查询部门信息
     */
    @ApiOperation(value = "分页查询部门信息")
    @GetMapping("/selectPage")
    public R<?> selectDeptPage(DeptQuery userQuery) {
        return R.ok(deptService.selectPage(userQuery));
    }

    /**
     * 获取ID和Name集合
     */
    @ApiOperation(value = "获取部门ID和Name集合")
    @GetMapping("/selectIdAndName")
    public R<?> selectDeptIdAndName() {
        return R.ok(deptService.selectIdAndName());
    }

}
